/*
 * 
 */
package com.apis.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//import com.imtt.insect.util.LoggerFactory;


public abstract class Action {	
	public abstract void execute(HttpServletRequest req, HttpServletResponse resp);
	
	protected String Request(HttpServletRequest req) {
		StringBuffer sb = new StringBuffer();
		sb.append(req.getRequestURI()).append("?");
		Enumeration<String> params = req.getParameterNames();
		while (params.hasMoreElements()) {
			String name = (String) params.nextElement();
			sb.append(name).append("=").append(req.getParameter(name))
					.append("&");
		}
		return sb.toString();
	} 
	
	protected void Response(HttpServletResponse resp, String data){
		Response(resp, data, "text/xml"); 
	}
	
	protected void Response(HttpServletResponse resp, String data, String respType) {
		resp.setContentType(respType);		
		try {
			PrintWriter out = resp.getWriter();
			out.println(data);
			out.flush();
		} catch (IOException e) {
			//LoggerFactory.getErrorLogger().debug(e.toString());
		} 
	}
	
	//text/html
	
	/**
	 * @return the actionID
	 */
	public abstract int getActionID();
}
